﻿
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Red.Controls.Depot.FileViewItemsProviders;
using Red.Controls.ViewModels;
using Red.Core;
using Red.Core.Containers;

namespace Red.Controls.Depot.ViewModels
{
    public abstract class DepotTreeItemAssetsBase : DepotTreeItem
    {
        private readonly int _depth;
        private List<string> _subFolders = new List<string>();

        public override bool IsExpandable
        {
            // TODO: write a proper logic here
            get { return _depth < 3; }
        }


        public DepotTreeItemAssetsBase( string title, Canvas icon, DepotTreeItem parent, DepotInfo depot, int depth = 0 ) 
            : base( title, "", icon, parent, depot )
        {
            // TODO: write a proper logic here
            // Generate some dummy data - We are recursively adding some sub-folders until we reach level 3
            _depth = depth;
            if ( IsExpandable )
            {
                _subFolders.Add( $"A{_depth}" );
                _subFolders.Add( $"B{_depth}" );
                _subFolders.Add( $"C{_depth}" );
            }
        }
        protected override Task EnumerateChildrenAsync( IRangedCollection<DataItem> children )
        {
            children.Clear();

            foreach ( string subFolder in _subFolders )
            {
                children.Add( new DepotTreeItemAssets( subFolder, this, _depot, _depth + 1 ) );
            }

            return Task.CompletedTask;
        }

        public override FileViewItemsProvider GetItemsProvider()
        {
            // The object we return here will be used to drive the right panel, so we're passing the same sub-folders as in EnumerateChildren
            return new AssetsItemsProvider( Path, _depot, _subFolders );
        }
    }


    public class DepotTreeItemAssetsRoot : DepotTreeItemAssetsBase
    {
        private static readonly Canvas _assetsIcon;
        private static readonly string _rootName = "[assets]";
        private static readonly string _bcPath = $"{{{_rootName},icon:appbar_diagram}}";

        public override string BreadcrumbPath
        {
            get { return _bcPath; }
        }

        public override string PathElement
        {
            get { return _rootName; }
        }

        static DepotTreeItemAssetsRoot()
        {
            _assetsIcon = (Canvas)Application.Current.FindResource( "appbar_diagram" );
        }

        public DepotTreeItemAssetsRoot( DepotTreeItem parent, DepotInfo depot, int depth = 0 ) 
            : base( "Assets View", _assetsIcon, parent, depot, 0 )
        {
        }
    }

    public class DepotTreeItemAssets : DepotTreeItemAssetsBase
    {
        public override string BreadcrumbPath
        {
            get { return ((DepotTreeItem)Parent).BreadcrumbPath + "\\" + PathElement; }
        }

        public DepotTreeItemAssets( string title, DepotTreeItem parent, DepotInfo depot, int depth ) 
            : base( title, _folderIcon, parent, depot, depth )
        {
        }

    }
}
